var $;
var layer;
var table;
var form;

    layui.use(['layer', 'table', 'form'], function () {
        layer = layui.layer;
        $ = layui.jquery;
        table = layui.table;
        form = layui.form;

        getTab();

        //初始化表格
        function getTab() {
            var id=$("#courseId").val();

            $.ajax({
                url:"/tea/selcourse",
                type:"post",
                dataType:"json",
                data:{"courseId":id},
                success:function(data){
                    if(data.code>-1){
                        $("#courseName").text(data.obj.courseName);//课程名称
                        var createDate=settime(data.obj.createDate);
                        $("#createDate").text(createDate);//上传时间
                        $("#createName").text(data.obj.createName);//上传人
                        $("#courseNprice").val(data.obj.courseNprice);//课程售价
                        $("#coursePrimary").val(data.obj.coursePrimary);//课程关键字
                        $("#courseCatory").val(data.obj.className);//课程分类
                        if(data.obj.likeNum){
                            $("#likeNum").val(data.obj.likeNum);//点赞量
                        }else{
                            $("#likeNum").val(0);
                        }
                        if(data.obj.collectNum){
                            $("#collectNum").val(data.obj.collectNum);//收藏量
                        }else{
                            $("#collectNum").val(0);
                        }
                        $("#commentNum").val(data.obj.commentNum);//评论量
                        $("#courseIntro").val(data.obj.courseIntro);//课程介绍
                        $("#img").attr("src",data.obj.url);//课程封面图url
                        var ht="<source src='"+data.obj.courseUrl+"' type='video/mp4' id='sourcId'/>\n" +
                            "                            <object data='"+data.obj.courseUrl+"' id='vidobjId'>\n" +
                            "                                <embed src='"+data.obj.courseUrl+"' id='embId'/>\n" +
                            "                            </object>"
                        $("#videId").html(ht);//课程视频
                    }
                },
                error: function () {
                    layer.msg('数据出错！');
                }
            });
        };

        /*日期转换*/
        function settime(da){
            var date=new Date(da);
            var year=date.getFullYear();
            var month=date.getMonth()+1;
            var day=date.getDate();
            var hours=date.getHours();
            var mm=date.getMinutes();
            var s=date.getSeconds();
            return year+'-'+add(month)+'-'+add(day)+' '+add(hours)+':'+add(mm)+':'+add(s);
            //return year+'-'+month+'-'+day+' '+hours+':'+mm+':'+s;
        };
        function add(time){//给非整数添0
            return time<10?'0'+time:time;
        };
    });